#!/bin/sh

# $FreeBSD$
#
# PROVIDE: %%PACKAGE_TARNAME%%
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# netifyd_enable (bool):    Set to NO by default.
#                           Set it to YES to enable netifyd.
# netifyd_opts (args):      Set manual configuration options.

. /etc/rc.subr

name="%%PACKAGE_TARNAME%%"
rcvar="${name}_enable"

command="%%PREFIX%%/sbin/${name}"
pidfile="/var/run/${name}/${name}.pid"

start_precmd="${name}_prestart"

export ASAN_OPTIONS=log_path=/var/run/${name}/${name}-asan.log:atexit=1

netifyd_prestart()
{
    . %%DATADIR%%/functions.sh

    case "$(detect_os)" in
    opnsense | pfsense)
        # OPNsense/pfSense detected, enable auto-detect:
        export NETIFYD_AUTODETECT="yes"
        netifyd_opts=$(auto_detect_options)
        ;;
    esac

    rc_flags="${netifyd_opts} ${rc_flags}"

    return 0
}

load_rc_config $name

: ${netifyd_enable:=no}

run_rc_command "$1"
